// add by yanyj 20180724 start
// 状态类

class State {
    constructor(state = {}, actions = {}) {
        this._state = state;
        this.actions = actions || {}; // key 表明对应state的key
        let _actions = this.actions;
        this.state = new Proxy(this._state, {
            set(target, proxy, value, obj) {
                // 简单对象不相等的时候才执行action
                console.log(target[proxy]);
                if(!Object.is(target[proxy], value)) {
                    pocket.isFunction(_actions[proxy]) && _actions[proxy](target, proxy, value, obj);
                    target[proxy] = value
                }
                return true;
            }
        });
    }

    setState(key, value) {
        // this._state[key] = value;
        this.state[key] = value;

        return this;
    }

    setActions(key, action) {
        this.actions[key] = action;
    }

}


// add by yanyj 20180724 end